﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using YArchitech.LIB.YJKControls;
using HYCodeBase.WinForm;

namespace HYIndicateDimension.BreakLine
{
	public partial class FormSelectDrawType : System.Windows.Forms.Form
	{
		public FormSelectDrawType(WindowHandle hWndRevit, int left, int top)
		{
			this.InitializeComponent();
			this.m_hWndRevit = hWndRevit;
			this.m_nSelection = 0;
			this.radioButton1.Checked = true;
			base.Location = new System.Drawing.Point(left, top);
		}

		private void FormSelectDrawType_FormClosed(object sender, FormClosedEventArgs e)
		{
			this.KeyEsc();
		}

		private void radioButton1_Click(object sender, EventArgs e)
		{
			if (this.m_nSelection == 0)
			{
				return;
			}
			this.m_nSelection = 0;
			this.ChangeOperateState();
		}

		private void radioButton2_Click(object sender, EventArgs e)
		{
			if (this.m_nSelection == 1)
			{
				return;
			}
			this.m_nSelection = 1;
			this.ChangeOperateState();
		}

		private void radioButton3_Click(object sender, EventArgs e)
		{
			if (this.m_nSelection == 2)
			{
				return;
			}
			this.m_nSelection = 2;
			this.ChangeOperateState();
		}

		private void ChangeOperateState()
		{
			Cursor.Position = new System.Drawing.Point(Cursor.Position.X, base.Bottom + 1);
			this.KeyEsc();
		}

		private void KeyEsc()
		{
			int wMsg = 7;
			FormSelectDrawType.SendMessage(this.m_hWndRevit.Handle, wMsg, IntPtr.Zero, IntPtr.Zero);
			int bVk = 27;
			int dwFlags = 0;
			int dwFlags2 = 2;
			FormSelectDrawType.keybd_event((byte)bVk, 0, dwFlags, 0);
			FormSelectDrawType.keybd_event((byte)bVk, 0, dwFlags2, 0);
		}

		[DllImport("user32.dll")]
		public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);

		[DllImport("user32.dll", EntryPoint = "SendMessageA")]
		public static extern int SendMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);

		public int m_nSelection;

		private WindowHandle m_hWndRevit;
	}
}
